﻿package display
{
	import controller.Controller;
	import fl.motion.Color;
	import flash.events.Event;
	
	import data.ItemData;
	import data.PresetData;
	
	import fl.controls.ColorPicker;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	
	public class DisplayScrollPane extends MovieClip
	{
		private var control:Controller;
		private var sh:Shell;
		
		private var data:Array;
		
		// preset item
		
		private var presetItem:PresetData;
		
		// movieclip
		
		private var button:DisplayTabBtn;
		private var buttonTwo:DisplayTabBtn;
		
		private var mc:MovieClip;
		
		//color
		
		private var bColor:uint = 0xffffff;
		private var wColor:uint = 0xcccccc;
		
		private var scrollPane:ScrollPane = new ScrollPane;
		
		public function DisplayScrollPane(shell:Shell,ctr:Controller,_data:Array,_presetItem:PresetData)
		{
			sh = shell;
			sh.stage.addEventListener(Event.RESIZE, onResize);
			
			control = ctr;
			data = _data;
			presetItem = _presetItem;
			
			ini();
		}
		
		private function ini():void
		{
			x = sh.stage.stageWidth - 285;
			y = 0;
			
			addButtons();
		}
		
		private function onResize(e:Event):void
		{
			x = sh.stage.stageWidth - 285;
			
			scrollPane.setSize(285, sh.stage.stageHeight);
		}
		
		private function addButtons():void
		{
			var yIndex:int = 0;
			var index:int = 0;
			
			var color:ColorTransform = new ColorTransform;
			
			mc = new MovieClip;
			
			for each(var item:ItemData in data)
			{
				if (index % 2)
				{
					color.color = bColor;
				}
				else 
				{
					color.color = wColor;
				}
				
				button = new DisplayTabBtn(item.name, item.type, item.category, item.itemCategory, control, presetItem);
				button.y = yIndex * 30;
				
				button.txt.text = item.name;
				button.bg.transform.colorTransform = color;
				
				
				mc.addChild(button);
				
				if (item.type == 'gradient')
				{
					yIndex +=2;
				}
				else
				{
					yIndex++;
				}
				
				index++;
			}
			
			scrollPane.setSize(285, sh.stage.stageHeight);
			
			addChild(scrollPane);
			addChild(mc);
			
			scrollPane.source = mc;
			
		}
	}
}